package com.contact.util.util.search;

import java.util.LinkedList;
import java.util.List;

import com.contact.util.util.collections.Utils;

/**
 * Apply the same type of data processing to data originating from multiple sources
 * 
 * @param <T>
 */
public class MultiSourcePageProcessor<T> extends PageProcessor<T> {

	private final List<DataProcessorSource<T>> dataSources = new LinkedList<DataProcessorSource<T>>();
	
	 public MultiSourcePageProcessor(int pageSize, DataProcessorSource<T>... sources) {
	        super(pageSize);
	        if (Utils.isEmpty(sources)) {
	        	throw new IllegalArgumentException("At least one source is required.");
	        }
	        for (DataProcessorSource<T> source : sources) {
	        	dataSources.add(source);
	        }
	    }
	 
	public void processAll(DataProcessor<T> dataProcessor) throws DataSourceException {
		for (DataProcessorSource<T> source : dataSources) {
			super.processAll(source, dataProcessor);
		}
	}
}
